import dayjs from "dayjs";

function getDayList(days = 10) {
  const _list: string[] = []
  for (let index = 0; index < days; index++) {
    _list.push(dayjs().add(index, 'day').format('YYYY-MM-DD'))
  }
  return _list
}

function getTimeList(start = 6, end = 23) {
  if (start >= end) start = end

  const _list: string[] = []
  for (let index = start; index <= end; index++) {
    _list.push(`${index > 9 ? index : "0" + index}:00`)
  }
  return _list
}

export function getRangList(startTime = dayjs().format('YYYY-MM-DD HH:mm')): string[][] {
  const nowDay = dayjs().format('YYYY-MM-DD'), paramsDay = dayjs(startTime).format('YYYY-MM-DD');
  const nowHour = Number(dayjs().format("HH")), startHour = Number(dayjs(startTime).format("HH"))
  const step = 2, start = ((nowDay !== paramsDay) || nowHour < 6) ? 6 : nowHour, end = 22
  const list: string[][] = [
    getDayList(),
    getTimeList(start, end - step),
    getTimeList(startHour + step, end),
  ]
  return list
}


export function fintIdx(value: string, l: string[]) {
  const _idx = l.findIndex(v => v === value)
  return _idx < 0 ? 0 : _idx
}


export function showDay(day: string) {
  const week = dayjs(day).format("dddd")
  if (day === dayjs().add(0, "days").format("YYYY-MM-DD")) {
    return `今天(${week})`
  }
  if (day === dayjs().add(1, "days").format("YYYY-MM-DD")) {
    return `明天(${week})`
  }
  return `${dayjs(day).format("MM-DD")}(${week})`
}